import { createRouter, createWebHistory } from "vue-router";

const routes = [
  {
    path: "/login",
    name: "login",
    component: () => import("./pages/login.vue"),
    meta: { requiresAuth: false },
  },
  {
    path: "/",
    component: () => import("./layouts/default.vue"),
    meta: { requiresAuth: true },
    children: [
      {
        path: "",
        name: "home",
        component: () => import("./pages/home.vue"),
        meta: { title: "应用中心", icon: "House" },
      },
      {
        path: "orders",
        name: "orders",
        component: () => import("./pages/orders/index.vue"),
        meta: { title: "订单管理", icon: "Document" },
      },
      {
        path: "dishes",
        name: "dishes",
        component: () => import("./pages/basic/dishes.vue"),
        meta: { title: "菜品管理", icon: "Food" },
      },
      //   {
      //     path: 'basic',
      //     name: 'basic',
      //     meta: { title: '基础管理', icon: 'Setting' },
      //     children: [
      //       {
      //         path: 'dishes',
      //         name: 'dishes',
      //         component: () => import('./pages/basic/dishes.vue'),
      //         meta: { title: '菜品管理', icon: 'Food' }
      //       }
      //     ]
      //   }
    ],
  },
];

const router = createRouter({
  history: createWebHistory(),
  routes,
});

// 路由守卫
router.beforeEach((to, from, next) => {
  // 检查页面是否需要认证
  if (to.meta.requiresAuth) {
    // TODO: 检查用户是否已登录
    // const isAuthenticated = ...
    // if (!isAuthenticated) {
    //   next('/login')
    //   return
    // }
  }
  next();
});

export default router;
